﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using Wicresoft.EKA.NRemedy.Linq;
using System.Configuration;
using System.Collections;
using BMC.ARSystem;

namespace Wicresoft.EKA.NRemedy.Test
{
    [TestClass]
    public class UnitTest4
    {

        [TestMethod]
        public void TestMethod2()
        {
            //string userLoginID = "wangjibin1";
            //ARLoginContextPool.Instance.Add(userLoginID, new ARLoginContext("135.251.45.87", userLoginID, "123"));

            string userLoginID = "Demo";
            ARLoginContextPool.Instance.Add(userLoginID, new ARLoginContext("135.251.45.103", userLoginID, "evm2@dev"));

            ARProxy<ASB_ResourceTicketAttachmentsModel> ar = new ARProxy<ASB_ResourceTicketAttachmentsModel>(
                new ARLoginContext("135.251.45.103", userLoginID, "evm2@dev"));
            ar.GetEntryWithFields("000000000000001", new System.Collections.Generic.List<uint>()
            {
              ASB_ResourceTicketAttachmentsModel.AttachmentField_ID,
              ASB_ResourceTicketAttachmentsModel.MimeType_ID,
              ASB_ResourceTicketAttachmentsModel.FileName_ID
            });

        }

        [TestMethod]
        public void TestMethod1()
        {
            string ARServer = ConfigurationManager.AppSettings["ARServer"];
            string ARUid = ConfigurationManager.AppSettings["ARUid"];
            string ARPwd = ConfigurationManager.AppSettings["ARPwd"];

            GlobalSettings.SetCharacterEncoding("UTF8");    //GlobalSetting 里面 
            ARLoginContext context = new ARLoginContext(ARServer, ARUid, ARPwd);
            ARProxy<TestModel> ar = new ARProxy<TestModel>(context);

            var ddd = ar.GetListEntry("1=1", new System.Collections.Generic.List<uint>() {
           TestModel.AssignedTo_ID,
           TestModel.RequestID_ID,
           TestModel.ShortDescription_ID
           });

            ddd[0].AssignedTo = "1";

            var dddddd = new TestModel();
            dddddd.AssignedTo = "1";
            //var x = context.ServerInstance.GetEntryStatistics("Test", null, TestModel.IntegerField_Name.S(), 2, 
            //    new int[] { (int)TestModel.Submitter_ID, (int)TestModel.ShortDescription_ID });

            //        var x = context.ServerInstance.GetEntryStatistics("Test", null, null, 1,
            //new int[] { (int)TestModel.Submitter_ID, (int)TestModel.ShortDescription_ID });

            //        ARSet<TestModel> arset = new ARSet<TestModel>();


            //        //group by
            //        //var entry = from a in arset
            //        //            where a.Submitter.StartsWith("Demo")
            //        //            orderby a.ShortDescription, a.Status descending
            //        //            group a by new { a.AssignedTo, a.CharacterField,a.CreateDate } into ddd
            //        //            select new { ddd.Key, ddddddd = ddd.Average(o => o.DecimalNumberField) };


            //        //select and page
            //        var entry = (from a in arset
            //                     where !a.Submitter.StartsWith("Demo")||(a.ShortDescription.EndsWith("END")&&a.ShortDescription.StartsWith("Start")||a.CreateDate<DateTime.Now)
            //                     orderby a.CreateDate descending, a.Status descending
            //                     select new { a.CreateDate, a.ShortDescription, a.RequestID }).Skip(0).Take(5);

            //        //select new { aa = a.ShortDescription, count = a.ShortDescription }).Skip(100).Take(100)


            //        var aa = entry.GetResult<TestModel>(context);

            for (int i = 0; i < 500; i++)
            {
                ar.CreateEntry(new TestModel()
                {
                    AssignedTo = "1",
                    CharacterField = "1111",
                    CheckBoxField = TestModel.CheckBoxField_Enum.Default1,
                    DateField = new DateValue(DateTime.Now),
                    DecimalNumberField = 1,
                    DiaryFieldSet = "1111111",
                    DropDownListField = TestModel.DropDownListField_Enum.Default1,
                    IntegerField = 1,
                    RadioButtonField = TestModel.RadioButtonField_Enum.Default1,
                    RealNumberField = 11,
                    Status = TestModel.Status_Enum.Closed,
                    Submitter = "1",
                    ShortDescription = "11111",
                    TimeField = new TimeOfDayValue(1, 1, 1)
                });
            }
            ar.CreateEntry(new TestModel()
            {
                AssignedTo = "1",
                CharacterField = "1111",
                CheckBoxField = TestModel.CheckBoxField_Enum.Default1,
                DateField = new DateValue(DateTime.Now),
                DecimalNumberField = 1,
                DiaryFieldSet = "1111111",
                DropDownListField = TestModel.DropDownListField_Enum.Default1,
                IntegerField = 1,
                RadioButtonField = TestModel.RadioButtonField_Enum.Default1,
                RealNumberField = 11,
                Status = TestModel.Status_Enum.Closed,
                Submitter = "1",
                ShortDescription = "11111",
                TimeField = new TimeOfDayValue(1, 1, 1)
            });

            var x1 = 1;

        }



        [TestMethod]
        public void TestMethod4()
        {
            string ARServer = ConfigurationManager.AppSettings["ARServer"];
            string ARUid = ConfigurationManager.AppSettings["ARUid"];
            string ARPwd = ConfigurationManager.AppSettings["ARPwd"];

            GlobalSettings.SetCharacterEncoding("UTF8");    //GlobalSetting 里面 
            ARLoginContext context = new ARLoginContext(ARServer, ARUid, ARPwd);
            ARProxy<ASB_CMDB_CIBaseInApplicationModel> ar = new ARProxy<ASB_CMDB_CIBaseInApplicationModel>(context);

            ar.CreateEntry(new ASB_CMDB_CIBaseInApplicationModel()
            {
                Name = "SVR-P-" + "dddd",
                BMCClassId = "BMC_COMPUTERSYSTEM",
                cChr_ApplicationRequestID = "fgsdfgsdgsd",
                cSel_Operation = ASB_CMDB_CIBaseInApplicationModel.cSel_Operation_Enum.New,
                cSel_AppStatus = ASB_CMDB_CIBaseInApplicationModel.cSel_AppStatus_Enum.Pending,
                Submitter = "ddddd",
                InstanceId = "",
            });

            var x1 = 1;

        }
    }   
}
